<!--
 入参：
 flowId： 流程id
 nodeId： 节点id
 flowInstId： 流程实例id
 nodeInstId： 节点实例id
 disableEditSubmit：新增/查看

-->
<template>
  <div>
    <div class="tl-form-line-title" v-if="visible">
      流程文件
    </div>
    <div style="padding-left:15px;" v-if="visible">
      <div class="toolbar">
        <el-badge :value="count" class="item">
          <el-button type="primary" size="small" plain @click.native="openFileListDialog('fileDialog')">流程文件</el-button>
        </el-badge>
      </div>
      <file-dialog ref="fileDialog" type="list" :flowid="flowid" :nodeid="nodeid" :flowinsid="flowinsid" :nodeinsid="nodeinsid" :disableEditSubmit="disableEditSubmit" @refresh="doRefresh"></file-dialog>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from "@tapui/mixins/mixin_list"
/** 子组件 */
import fileDialog from "./dialog"
/** 工具类 */
import { getAction, putAction } from "@tapui/utils/http"

/** VUE配置 */
export default {
  mixins: [mixin_list],
  components: { fileDialog },
  data() {
    return {
      moduleTitle: "流程文件",
      urlPrefix: "/base/flowFileIns/",
      url: {
        count: "",
        queryLlowFileCount: "/base/flowFile/count",
        queryLlowFileInsCount: "/base/flowFileIns/count"
      },
      model: {},
      tableHeight: 0,
      sourceType: "",
      flowid: 0,
      nodeid: 0,
      flowinsid: 0,
      nodeinsid: 0,
      disableEditSubmit: false,
      visible: false,
      count: 0
    }
  },
  props: {},
  methods: {
    openFileListDialog(editForm) {
      this.$refs[editForm].disableEditSubmit = this.disableEditSubmit
      this.$refs[editForm].visible = true
    },
    open() {
      let params = {}
      params.flow_id = this.flowid
      params.node_id = this.nodeid
      params.flow_inst_id = this.flowinsid
      params.node_inst_id = this.nodeinsid
      if (!this.disableEditSubmit) {
        this.url.count = this.url.queryLlowFileCount
      } else {
        this.url.count = this.url.queryLlowFileInsCount
      }
      getAction(this.url.count, params)
        .then((res) => {
          if (res.success) {
            this.count = res.result
          } else {
            this.$tap.alert(res.message, "warning")
          }
          if (this.count === 0) {
            this.visible = false
            return
          }
          this.visible = true
        })
        .catch(() => {})
    },
    asynSave(resolve, reject) {
      if (this.visible === true) {
        this.$refs.fileDialog.asynSave(resolve, reject)
      } else {
        resolve()
      }
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$emit("mounted")
      this.visible = false
    })
  },
  created() {}
}
</script>
<style scoped></style>
